package net.huashitong.zhApp.controller;

import jodd.util.StringUtil;
import net.huashitong.user.entity.BnpUser;
import net.huashitong.user.filter.BnpUserFilter;
import net.huashitong.user.service.BnpUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public abstract class BaseCtrl {
    @Autowired
    private BnpUserService bnpUserService;

    public BnpUser queryUserAuth(String userPhone) {
        if(StringUtil.isBlank(userPhone)){
            return null;
        }
        BnpUserFilter bnpUserFilter = new BnpUserFilter();
        bnpUserFilter.setPhone(userPhone);
        List<BnpUser> userList = bnpUserService.queryByFilter(bnpUserFilter);
        if (userList.size() > 0) {
            return userList.get(0);
        }else{
            return null;
        }
    }

    public Map<String, Object> coverMessage(String code, String msg, Object data, Object count) {
        Map<String, Object> message = new HashMap<>();
        message.put("code",code);
        message.put("message",msg);
        message.put("data",data);
        message.put("count",count);
        return message;
    }

    public Map<String, Object> coverMessage(String code, String msg, Object data) {
        Map<String, Object> message = new HashMap<>();
        message.put("code",code);
        message.put("message",msg);
        message.put("data",data);
        return message;
    }

    public Map<String, Object> coverMessage(String code, String msg) {
        Map<String, Object> message = new HashMap<>();
        message.put("code",code);
        message.put("message",msg);
        return message;
    }
}
